package com.running.mobile;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.isomorphic.rpc.RPCManager;
import com.isomorphic.servlet.IDACall;
import com.isomorphic.servlet.RequestContext;

public class SecureIDACall extends IDACall {
	  
    public void processRequest(HttpServletRequest request,
            HttpServletResponse response)
     throws ServletException, IOException
    {
        HttpSession session = request.getSession();
        Object roles = session == null ? null : session.getAttribute("roles");

        if (roles != null) {
            try {
                RequestContext context = RequestContext.instance(this, request, response);   
                RPCManager rpc = new RPCManager(request, response);
                rpc.setAuthenticated(true);
                rpc.setUserRoles((String) roles); 
                
                // call processRPCTransaction() to iterate through all RPCRequests and
                // DSRequests and execute them
                processRPCTransaction(rpc, context);

            } catch (Throwable e) {
                handleError(response, e);
            }
        } else {
        	response.sendRedirect("../login.jsp");
        } 
    }
}